App({
  globalData: {
    enums: {
      responsibilityOptions: [
        { label: '自己', value: 'self' },
        { label: '对方', value: 'partner' },
        { label: '双方各半', value: 'both' },
        { label: '其他原因', value: 'other' }
      ],
      statusOptions: [
        { label: '已解决', value: 'resolved' },
        { label: '未解决', value: 'unresolved' },
        { label: '进行中', value: 'in-progress' }
      ],
      tagOptions: ['家务', '财务', '工作', '家庭', '旅行', '社交', '生活习惯', '沟通问题'],
      couponOptions: [
        { label: '电影观看券', value: 'movie', icon: '/images/movie.png' },
        { label: '奶茶兑换券', value: 'bubble-tea', icon: '/images/bubble-tea.png' },
        { label: '家务补偿券', value: 'housework', icon: '/images/housework.png' },
        { label: '按摩服务券', value: 'massage', icon: '/images/massage.png' }
      ],
      conflictLabels: ['轻微', '低', '中等', '高', '严重'],
      statusTexts: {
        resolved: '已解决',
        unresolved: '未解决',
        'in-progress': '进行中'
      }
    },
    records: [] // 全局吵架记录数据
  },
  
  onLaunch() {
    this.loadRecords();
  },
  
  // 从本地存储加载记录
  loadRecords() {
    try {
      const records = wx.getStorageSync('conflictRecords');
      if (records) {
        this.globalData.records = records;
      }
    } catch (e) {
      console.error('加载记录失败:', e);
    }
  },
  
  // 保存记录到本地存储
  saveRecords() {
    try {
      wx.setStorageSync('conflictRecords', this.globalData.records);
    } catch (e) {
      console.error('保存记录失败:', e);
    }
  },
  
  // 添加新记录
  addRecord(record) {
    const newRecord = {
      ...record,
      id: Date.now().toString(), // 使用时间戳作为唯一ID
      createdAt: new Date().toISOString() // 记录创建时间
    };
    
    this.globalData.records.unshift(newRecord); // 添加到开头
    this.saveRecords();
    return newRecord;
  },
  
  // 更新记录
  updateRecord(id, updatedRecord) {
    const index = this.globalData.records.findIndex(r => r.id === id);
    if (index !== -1) {
      this.globalData.records[index] = {
        ...this.globalData.records[index],
        ...updatedRecord
      };
      this.saveRecords();
      return true;
    }
    return false;
  },
  
  // 删除记录
  deleteRecord(id) {
    const index = this.globalData.records.findIndex(r => r.id === id);
    if (index !== -1) {
      this.globalData.records.splice(index, 1);
      this.saveRecords();
      return true;
    }
    return false;
  },
  
  // 获取所有记录
  getAllRecords() {
    return this.globalData.records;
  },
  
  // 根据ID获取记录
  getRecordById(id) {
    return this.globalData.records.find(r => r.id === id);
  }
});